<!-- 侧边栏菜单 item license by http://eleadmin.com -->
<template>
  <el-submenu
    v-if="haveChildren"
    :index="item.menuId+'_item'"
    :popper-class="popClass"
    :popper-append-to-body="false">
    <template slot="title">
      <i v-if="item.meta.icon" :class="item.meta.icon"></i>
      <span slot="title">{{ item.meta.title }}</span>
    </template>
    <template v-for="child in item.children">
      <my-sidebar-item
        v-if="!child.meta.hide"
        :key="child.path"
        :item="child"
        :pop-class="popClass"/>
    </template>
  </el-submenu>
  <el-menu-item v-else :index="item.path || ''">
    <a
      v-if="isUrl"
      :href="item.path"
      target="_blank"
      @click.stop="">
      <i v-if="item.meta.icon" :class="item.meta.icon" :title="item.meta.title"></i>
      <span>{{ item.meta.title}}</span>
    </a>
    <router-link v-else :to="item.path">
      <i v-if="item.meta.icon" :class="item.meta.icon" :title="item.meta.title"></i>
      <span>{{ item.meta.title }}</span>
    </router-link>
  </el-menu-item>
</template>

<script>
import util from 'ele-admin/packages/util.js';

export default {
  name: 'MySidebarItem',
  props: {
    item: {
      type: Object,
      required: true
    },
    popClass: String
  },
  computed: {
    /* 是否有子级 */
    haveChildren() {
      return !!(this.item.children && this.item.children.filter((d) => !d.meta.hide).length);
    },
    /* 是否是网址 */
    isUrl() {
      return util.isUrl(this.item.path);
    }
  }
}
</script>
